package com.datastructure.test.longestlengthserialofcontainstwochar;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class LongestLengthSerialOfContainsTwoChar {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextLine()) {
            String word = sc.nextLine();

            int n = word.length();

            int left = 0, right = 0;
            int ans = 0;

            Map<Character, Integer> map = new HashMap<>();

            while (right < n) {
                char c = word.charAt(right);
                map.put(c, map.getOrDefault(c, 0) + 1);

                while (map.size() > 2 && left < right) {
                    char leftC = word.charAt(left);
                    map.put(leftC, map.getOrDefault(leftC, 0) - 1);
                    if (map.get(leftC) == 0) {
                        map.remove(leftC);
                    }
                    left++;
                }

                ans = Math.max(ans, right - left + 1);
                right++;
            }

            System.out.println(ans);
        }
    }

    private static int computeMaxLength(int i, char[] charArray) {
        int result = 1;
        int secondResult=1;
        for (int j = i+1; j < charArray.length; j++) {
            if(charArray[j]==charArray[i]){
                result++;
            }else {
                if(j+1< charArray.length&&charArray[j]==charArray[j +1]){
                    for (int g = j +1; g < charArray.length; g++) {
                        if(charArray[g]==charArray[j]){
                            secondResult++;
                        } else {
                            return result+secondResult;
                        }
                    }
                }else {
                    break;
                }
            }
        }
        result++;
        return result;
    }
}
